#include <bits/stdc++.h>
using namespace std;
void solve(){
    long long n;
    cin>>n;
    long long a[200005];
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    char s[200005]={'&'};
    string cn="Red";
    bool flag=false;
    for (int i=0;i<n;i++){
            flag=false;
        for (int j=i;j<n;j++){
            if (a[i]==a[j]&&i!=j&&i<j){
                s[i]=cn[0];
                s[j]=cn[0];
                //cout<<i<<" "<<j<<endl;
                if (cn=="Red")cn="Blue";
                else cn="Red";
                flag=true;
            }
        }
        if (flag==false&&s[i]=='&'){
            //cout<<i<<endl;
            s[i]=cn[0];
            if (cn=="Red")cn="Blue";
            else cn="Red";
        }
    }
    s[n-1]='R';
    //cout<<s<<endl;
    long long c[200005]={0};
    for (long long i=0;i<n;i++){
        for (long long j=i;j>=0;j--){
            if (s[i]==s[j]&&a[i]==a[j]&&i!=j){
                c[i]=a[i];
            }
        }
    }
    long long sum=0;
    for (long long i=0;i<n;i++){
        sum+=c[i];
        //cout<<c[i]<<endl;

    }
    cout<<sum<<endl;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    while (t--){
        solve();
    }
    return 0;
}
